﻿using System.Windows;
using Microsoft.Windows.Controls;

namespace Sinacor.Infra.UI.Controls.SmartClient.DataGrid
{
	public class DataGridColumnHeader : Microsoft.Windows.Controls.Primitives.DataGridColumnHeader
	{
		public DataGridColumnHeader()
		{
			this.Loaded += new RoutedEventHandler(DataGridColumnHeader_Loaded);
			this.Unloaded += new RoutedEventHandler(DataGridColumnHeader_Unloaded);
		}

		void DataGridColumnHeader_Loaded(object sender, RoutedEventArgs e)
		{
			if (this.Column != null)
			{
				object headerProperty = this.Column.ReadLocalValue(DataGridColumn.HeaderProperty);

				if(headerProperty != null)
					this.SetValue(DataGridColumnHeader.ContentProperty, headerProperty);
				else
					this.ClearValue(DataGridColumnHeader.ContentProperty);
			}
		}

		void DataGridColumnHeader_Unloaded(object sender, RoutedEventArgs e)
		{
			this.ClearValue(DataGridColumnHeader.ContentProperty);
		}
	}
}
